﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyProFile_V2
{
    public partial class FloderDo : Form
    {
        MainForm mainForm = null;
        private bool isEdit = false;

        public bool IsEdit
        {
            get { return isEdit; }
            set { isEdit = value; }
        }
        public FloderDo()
        {
            InitializeComponent();
        }

        private void FloderDo_Load(object sender, EventArgs e)
        {
            mainForm = (MainForm)this.Owner;
            if (IsEdit)
            {
                this.txt_floderName.Text = mainForm.tv_proTree.SelectedNode.Text;
                this.btn_submit.Text = "修 改";

            }
            else
            {
                this.btn_submit.Text = "添 加";
            }

        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txt_floderName.Text))
            {

                TreeNode tn = new TreeNode();
                tn.Name = this.txt_floderName.Text;
                tn.Text = this.txt_floderName.Text;
                if (mainForm.tv_proTree.Nodes.ContainsKey(this.txt_floderName.Text))
                {
                    MessageBox.Show("已包含此项");
                    return;
                }
                if (IsEdit)
                {
                    mainForm.tv_proTree.SelectedNode.Text = tn.Text;
                }
                else
                {
                    mainForm.tv_proTree.Nodes.Add(tn);
                    this.txt_floderName.Text = "";
                    this.txt_floderName.Focus();
                }
                

            }
            else
            {
                MessageBox.Show("文件夹不能为空");
            }
        }

       

      

        
    }
}